#include <QDebug>

#include "tasktabitemwidget.h"
#include "bizlogic/taskmanager.h"
#include "taskitem.h"
#include "widgets/moreactionwidget.h"

TaskTabItemWidget::TaskTabItemWidget(QWidget *parent) :
    CVTabItem(parent)
{
}

void TaskTabItemWidget::load()
{
    loadTasks();
}

void TaskTabItemWidget::loadTasks()
{
    TaskManager *taskMgr = new TaskManager();
    taskMgr->getTasks();
    connect(taskMgr, SIGNAL(handleTasks(QList<Task*>)), this, SLOT(handleTasksSlot(QList<Task*>)));
}

void TaskTabItemWidget::handleTasksSlot(QList<Task *> list)
{
    qDebug() << ">>>Disply tasks....";

    this->getList()->clear();

    int size = list.size();
    if (size != 0)
    {
        for (int i = 0; i < size; ++i)
        {
            Task *task = list.at(i);
            //qDebug() << task->getAttributeValue(Task::TITLE);
            //qDebug() << task->getAttributeValue(Task::DESCRIPTION);
            TaskItem *item = new TaskItem();
            item->setTask(task);
            QWidget *widget = qobject_cast<QWidget*>(item);
            this->getList()->appendItem(widget);
        }
    }
    else
    {
        MoreActionWidget *mWidget = new MoreActionWidget();
        mWidget->setDisplayText("No Action Items found");
        this->getList()->appendItem(mWidget);
    }
    this->getList()->addStretch();

}


